package com.zdsoft.finance.evaluate.service.impl;

import com.zdsoft.finance.base.service.impl.BaseServiceImpl;
import com.zdsoft.finance.common.exception.BusinessException;
import com.zdsoft.finance.evaluate.entity.ProjectEvaluate;
import com.zdsoft.finance.evaluate.entity.ProjectEvaluateFirst;
import com.zdsoft.finance.evaluate.repository.ProjectEvaluateFirstRepository;
import com.zdsoft.finance.evaluate.repository.ProjectEvaluateRepository;
import com.zdsoft.finance.evaluate.service.ProjectEvaluateService;
import com.zdsoft.framework.core.common.util.ObjectHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 项目评审service
 *
 * @author LiaoGuoWei
 * @create 2016-10-19 14:47
 **/
@Service("projectEvaluateService")
public class ProjectEvaluateServiceImpl extends BaseServiceImpl<ProjectEvaluate,ProjectEvaluateRepository> implements ProjectEvaluateService {

       @Autowired
       private ProjectEvaluateRepository projectEvaluateRepository;
//
//       @Resource
//       private BusiFormService busiFormService;
//
       @Autowired
       private ProjectEvaluateFirstRepository projectEvaluateFirstRepository;

//
//       @Log
//       Logger logger;
//
//
//       @Override
//       public ProjectEvaluate findById(String id) throws BusinessException {
//              if (ObjectHelper.isNotEmpty(id)) {
//                     return this.projectEvaluateRepository.findOne(id);
//              } else {
//                     throw new BusinessException("1001001", "按照ID查询项目评审出错!参数为空");
//              }
//       }
//
//       @Override
//       public ProjectEvaluate findProEvalByProjectCd(String projectCd) throws BusinessException {
//              if (ObjectHelper.isNotEmpty(projectCd)) {
//                     ProjectEvaluate sourceData = this.projectEvaluateRepository.findByProjectCdAndIsDeleted(projectCd, false);
//                     return sourceData;
//              } else {
//                     throw new BusinessException("1001001", "按照项目编号查找出错！参数为空");
//              }
//       }
//
//       @Override
//       public List<ProjectEvaluate> findByCondition(Map<String, Object> condition) throws BusinessException {
//              Map<String, Object> qryCondition = new HashMap<>();
//              StringBuffer hql = new StringBuffer(" select p from ProjectEvaluate p where p.isDeleted= :isDeleted ");
//              qryCondition.put("isDeleted", !BaseEntity.DELETED);
//              // 客户编号
//              if (ObjectHelper.isNotEmpty(condition.get("clientCd"))) {
//                     hql.append(" and p.clientCd=:clientCd ");
//                     qryCondition.put("clientCd", condition.get("clientCd"));
//              }
//              // 客户名称
//              if (ObjectHelper.isNotEmpty(condition.get("clientNm"))) {
//                     hql.append(" and p.clientNm like :clientNm ");
//                     qryCondition.put("clientNm", "%" + condition.get("clientNm") + "%");
//              }
//              // 项目编号
//              if (ObjectHelper.isNotEmpty(condition.get("projectCd"))) {
//                     hql.append(" and p.projectCd=:projectCd ");
//                     qryCondition.put("projectCd", condition.get("projectCd"));
//              }
//              // 项目名称
//              if (ObjectHelper.isNotEmpty(condition.get("projectNm"))) {
//                     hql.append(" and p.projectNm like :projectNm ");
//                     qryCondition.put("projectNm", "%" + condition.get("projectNm") + "%");
//              }
//              // 决议编号
//              if (ObjectHelper.isNotEmpty(condition.get("resolutionCd"))) {
//                     hql.append(" and p.resolutionCd = :resolutionCd ");
//                     qryCondition.put("resolutionCd", condition.get("resolutionCd"));
//              }
//              // 纪要编号
//              if (ObjectHelper.isNotEmpty(condition.get("summaryCd"))) {
//                     hql.append(" and p.summaryCd = :summaryCd ");
//                     qryCondition.put("summaryCd", condition.get("summaryCd"));
//              }
//              // 业务编号
//              if (ObjectHelper.isNotEmpty(condition.get("busiCd"))) {
//                     hql.append(" and p.busiCd like :busiCd ");
//                     qryCondition.put("busiCd", "%" + condition.get("busiCd") + "%");
//              }
//              // 项目评审类型
//              if (ObjectHelper.isNotEmpty(condition.get("projectType"))) {
//                     hql.append(" and p.projectType =:projectType ");
//                     qryCondition.put("projectType", condition.get("projectType"));
//              }
//              hql.append(" order by p.createTime desc ");
//              return this.projectEvaluateRepository.findByHql(hql.toString(), qryCondition);
//       }
//
//       @Override
//       public Page<ProjectEvaluate> findByConditionPage(PageRequest page, Map<String, Object> condition)
//               throws BusinessException {
//              Map<String, Object> qryCondition = new HashMap<>();
//              StringBuffer hql = new StringBuffer(" select p from ProjectEvaluate p where p.isDeleted= :isDeleted ");
//              qryCondition.put("isDeleted", !BaseEntity.DELETED);
//              // 客户编号
//              if (ObjectHelper.isNotEmpty(condition.get("clientCd"))) {
//                     hql.append(" and p.clientCd=:clientCd ");
//                     qryCondition.put("clientCd", condition.get("clientCd"));
//              }
//              // 客户名称
//              if (ObjectHelper.isNotEmpty(condition.get("clientNm"))) {
//                     hql.append(" and p.clientNm like :clientNm ");
//                     qryCondition.put("clientNm", "%" + condition.get("clientNm") + "%");
//              }
//              // 项目编号
//              if (ObjectHelper.isNotEmpty(condition.get("projectCd"))) {
//                     hql.append(" and p.projectCd=:projectCd ");
//                     qryCondition.put("projectCd", condition.get("projectCd"));
//              }
//              // 项目名称
//              if (ObjectHelper.isNotEmpty(condition.get("projectNm"))) {
//                     hql.append(" and p.projectNm like :projectNm ");
//                     qryCondition.put("projectNm", "%" + condition.get("projectNm") + "%");
//              }
//              // 决议编号
//              if (ObjectHelper.isNotEmpty(condition.get("resolutionCd"))) {
//                     hql.append(" and p.resolutionCd = :resolutionCd ");
//                     qryCondition.put("resolutionCd", condition.get("resolutionCd"));
//              }
//              // 纪要编号
//              if (ObjectHelper.isNotEmpty(condition.get("summaryCd"))) {
//                     hql.append(" and p.summaryCd = :summaryCd ");
//                     qryCondition.put("summaryCd", condition.get("summaryCd"));
//              }
//              // 业务编号
//              if (ObjectHelper.isNotEmpty(condition.get("busiCd"))) {
//                     hql.append(" and p.busiCd like :busiCd ");
//                     qryCondition.put("busiCd", "%" + condition.get("busiCd") + "%");
//              }
//              // 项目评审类型
//              if (ObjectHelper.isNotEmpty(condition.get("projectType"))) {
//                     hql.append(" and p.projectType =:projectType ");
//                     qryCondition.put("projectType", condition.get("projectType"));
//              }
//              hql.append(" order by p.createTime desc ");
//              return this.projectEvaluateRepository.findByHqlPage(page, hql.toString(), qryCondition);
//       }
//
//	/*
//      * @Override public ProjectEvaluate findByBusiFormNo(String busiFormNo)
//	 * throws BusinessException { if (ObjectHelper.isNotEmpty(busiFormNo)) {
//	 * return this.projectEvaluateRepository.findWithBusiFormNo(busiFormNo); }
//	 * else { throw new BusinessException("1001001",
//	 * "通过busiFormNo查找项目评审单出错！参数为空"); } }
//	 */
//
//       @Override
//       @Transactional
//       public ProjectEvaluate saveProjectEvaluate(ProjectEvaluate projectEvaluate) {
//              projectEvaluate.setCreateTime(new Date());
//              ProjectEvaluate evaluate = this.projectEvaluateRepository.save(projectEvaluate);
//              return evaluate;
//       }
//
//       // @Override
//       // @Transactional
//       // public ProjectEvaluate saveProEval(ProjectEvaluate projectEvaluate)
//       // throws BusinessException {
//       // if(ObjectHelper.isNotEmpty(projectEvaluate)){
//       // //如果关联的busiform表不为空
//       // if(ObjectHelper.isNotEmpty(projectEvaluate.getBusiForm())){
//       // //更新busiform表
//       // BusiForm
//       // busiForm=this.saveOrUpdateBusiForm(projectEvaluate.getBusiForm());
//       // //清空关联 避免事务控制失败
//       // projectEvaluate.setBusiForm(null);
//       // //更新项目评审
//       // projectEvaluate=this.projectEvaluateRepository.save(projectEvaluate);
//       // //建立关联
//       // projectEvaluate.setBusiForm(busiForm);
//       // //更新
//       // projectEvaluate=this.projectEvaluateRepository.save(projectEvaluate);
//       // return projectEvaluate;
//       // }else{
//       // projectEvaluate.setCreateTime(new Date());
//       // return this.projectEvaluateRepository.save(projectEvaluate);
//       // }
//       // }else {
//       // throw new BusinessException("1001001","保存项目评审单出错！参数为空");
//       // }
//       // }
//
//       @Override
//       @Transactional
//       public ProjectEvaluate updateProEval(ProjectEvaluate projectEvaluate) throws BusinessException {
//              if (ObjectHelper.isNotEmpty(projectEvaluate)) {
//                     if (ObjectHelper.isNotEmpty(projectEvaluate.getId())) {
//                            // 查询出需要更新的对象
//                            ProjectEvaluate old = this.projectEvaluateRepository.findOne(projectEvaluate.getId());
//                            // 将更改后的值赋予需要更改的对象
//                            old = (ProjectEvaluate) ObjectProperUtil.compareAndValue(projectEvaluate, old);
//                            // 执行更新并返回值
//                            return this.projectEvaluateRepository.updateEntity(old);
//                     } else {
//                            throw new BusinessException("1001001", "修改项目评审单出错！参数不合法，参数ID为空");
//                     }
//              } else {
//                     throw new BusinessException("1001001", "修改项目评审单出错！参数为空");
//              }
//       }
//
//       @Override
//       @Transactional
//       public ProjectEvaluate deleteProEval(String id) throws BusinessException {
//              if (ObjectHelper.isNotEmpty(id)) {
//                     ProjectEvaluate evaluate = this.projectEvaluateRepository.getOne(id);
//                     evaluate.setIsDeleted(true);
//                     evaluate.setDeleteTime(new Date());
//                     int result = this.projectEvaluateRepository.deleteProjectEvaluate(id);
//                     // evaluate=this.entityManager.merge(evaluate);
//                     // entityManager.flush();
//                     return evaluate;
//              } else {
//                     throw new BusinessException("1001001", "删除项目评审单出错！参数为空");
//              }
//       }
//
       @Override
       public String getActualEvaluateUrl(ProjectEvaluateFirst evaluateFirst) throws BusinessException {
              String url="http://192.168.33.163:8080/web/admin/floatingLoanEvaluate/evaluateDirectEdit";
              return url;
       }

       @Override
       @Transactional
       public ProjectEvaluateFirst saveProjectEvaluateFirat(ProjectEvaluateFirst evaluateFirst) throws BusinessException {
              return this.projectEvaluateFirstRepository.saveEntity(evaluateFirst);
       }

       @Override
       public ProjectEvaluateFirst findEvaluateFirstById(String id) throws BusinessException {
              if(ObjectHelper.isNotEmpty(id)){
                     return this.projectEvaluateFirstRepository.getOne(id);
              }else {
                     throw new BusinessException("10010004","传入参数为空");
              }
       }

       @Override
       @Transactional
       public ProjectEvaluate saveProjectEvaluate(ProjectEvaluate projectEvaluate) throws BusinessException {
              if(ObjectHelper.isNotEmpty(projectEvaluate)){
                     return this.projectEvaluateRepository.saveEntity(projectEvaluate);
              }else {
                     throw new BusinessException("10010004","传入参数为空");
              }
       }

       @Override
       public ProjectEvaluate findProjectEvaluateById(String id) throws BusinessException {
              if(ObjectHelper.isNotEmpty(id)){
                     ProjectEvaluate projectEvaluate=this.projectEvaluateRepository.findOne(id);
                     if(ObjectHelper.isNotEmpty(projectEvaluate)){
                            return projectEvaluate;
                     }else{
                            throw new BusinessException("10010002","根据相应参数未找到相应的数据");
                     }
              }else{
                     throw new BusinessException("10010004","传入参数为空");
              }
       }

       //
//       /********************************** 私有方法集 ***************************************************************************************************/
//
//       /**
//        * 更新或保存BusiForm
//        *
//        * @param busiForm
//        * @return
//        */
//       private BusiForm saveOrUpdateBusiForm(BusiForm busiForm) throws BusinessException {
//              if (ObjectHelper.isNotEmpty(busiForm)) {
//                     if (ObjectHelper.isNotEmpty(busiForm.getId())) {
//                            return this.busiFormService.update(busiForm);
//                     } else {
//                            return this.busiFormService.save(busiForm);
//                     }
//              } else {
//                     throw new BusinessException("1001001", "projectEvaluateService更新或保存BusiForm出错！参数为空");
//              }
//       }
//
//       /**
//        * 更新项目评审
//        *
//        * @param projectEvaluate 项目评审
//        * @return
//        * @throws BusinessException
//        */
//       private ProjectEvaluate updateProjectEvaluate(ProjectEvaluate projectEvaluate) throws BusinessException {
//              if (ObjectHelper.isNotEmpty(projectEvaluate) && ObjectHelper.isNotEmpty(projectEvaluate.getId())) {
//                     ProjectEvaluate evaluate = this.projectEvaluateRepository.getOne(projectEvaluate.getId());
//                     // 比对更改的属性值
//                     evaluate = (ProjectEvaluate) ObjectProperUtil.compareAndValue(projectEvaluate, evaluate);
//
//                     evaluate = this.projectEvaluateRepository.save(evaluate);
//                     return evaluate;
//              } else {
//                     throw new BusinessException("1001001", "更新项目评审出错！参数为空");
//              }
//       }

}
